package cn.myweixin.test;

import java.net.URLEncoder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.myweixin.po.menu.Button;
import cn.myweixin.po.menu.CommonButton;
import cn.myweixin.po.menu.ComplexButton;
import cn.myweixin.po.menu.Menu;
import cn.myweixin.po.menu.ViewButton;

import cn.myweixin.util.WeixinUtil;

public class MenuManager {
	
	private static Logger log = LoggerFactory.getLogger(MenuManager.class);  
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
	            // 调用接口创建菜单  
	            int result = WeixinUtil.createMenu(getMenu());  
	            // 判断菜单创建结果  
	            if (0 == result)  
	                log.info("菜单创建成功！");  
	            else  
	                log.info("菜单创建失败，错误码：" + result);  
	         
	}
	/** 
     * 组装菜单数据 
     *  
     * @return 
     */  
    private static Menu getMenu() {  
    	ViewButton btn11=new ViewButton();
    	btn11.setName("培训通知");
    	btn11.setType("view");
    	btn11.setUrl("http://nonmin.applinzi.com/notice/noticelist.action");
    	//btn11.setUrl("http://n167337a93.iask.in/weiApp/notice/noticelist.action");
    	
    	ViewButton btn12=new ViewButton();
    	btn12.setName("培训报名");
    	btn12.setType("view");
    	btn12.setUrl("http://nonmin.applinzi.com/notice/querysigns.action");
    	//btn12.setUrl("http://n167337a93.iask.in/weiApp/notice/querysigns.action");
    	
    	
    	ViewButton btn21=new ViewButton();
    	btn21.setName("视频学习");
    	btn21.setType("view");
    	btn21.setUrl("http://nonmin.applinzi.com/video/queryvideos.action");
    	//btn21.setUrl("http://n167337a93.iask.in/weiApp/video/queryvideos.action");
    	
    	
    	ViewButton btn22=new ViewButton();
    	btn22.setName("课件学习");
    	btn22.setType("view");
    	btn22.setUrl("http://nonmin.applinzi.com/ListFileServlet");
    	//btn22.setUrl("http://n167337a93.iask.in/weiApp/ListFileServlet");
    	
    	ViewButton  btn23=new ViewButton();
    	btn23.setName("在线测试");
    	btn23.setType("view");
    	btn23.setUrl("http://nonmin.applinzi.com/test.jsp");
    	//btn23.setUrl("http://n167337a93.iask.in/weiApp/test.jsp");
    	

    	ViewButton btn31=new ViewButton();
    	btn31.setName("用户登陆");
    	btn31.setType("view");
    	 btn31.setUrl("http://nonmin.applinzi.com/user/validate.action");
    	//btn31.setUrl("http://n167337a93.iask.in/weiApp/user/validate.action");
    	
    	ViewButton  btn32=new ViewButton();
    	btn32.setName("问卷调查");
    	btn32.setType("view");
    	btn32.setUrl("http://nonmin.applinzi.com/test.jsp");
      	//btn32.setUrl("http://n167337a93.iask.in/weiApp/test.jsp");
      	
    	
    	
       
        ComplexButton mainBtn1 = new ComplexButton();  
        mainBtn1.setName("培训指南");  
        mainBtn1.setSub_button(new  ViewButton[] { btn11, btn12 });  
  
        ComplexButton mainBtn2 = new ComplexButton();  
        mainBtn2.setName("在线课堂");  
        mainBtn2.setSub_button(new ViewButton[] { btn21, btn22 ,btn23});  
  
        ComplexButton mainBtn3=new ComplexButton();
        mainBtn3.setName("用户中心");
        mainBtn3.setSub_button(new ViewButton[] {btn31,btn32});
       
  
        /** 
         * 这是公众号xiaoqrobot目前的菜单结构，每个一级菜单都有二级菜单项<br> 
         *  
         * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br> 
         * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br> 
         * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 }); 
         */  
        Menu menu = new Menu();  
        menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 });  
  
        return menu;  
    }  
 
}
